#pragma once

#include <string>

std::string multiply(std::string a, std::string b) {
    std::string mul;
    const std::string & shorter = a.size() <= b.size() ? a : b;
    const std::string longer = std::string(shorter.size(), '0') + ( std::addressof(shorter) == std::addressof(a) ? b : a);
    int result = 0;
    for( auto idx = 0; idx < longer.size(); idx++ ){
        for( auto longIdx = idx, shortIdx = 0; longIdx >= 0 && shortIdx < shorter.size() ; shortIdx++, longIdx-- ){
            result += ( longer[longer.size() - 1 - longIdx] - '0' ) * ( shorter[shorter.size() - 1 - shortIdx] - '0' );
        }
        mul.push_back(result % 10 + '0');
        result /= 10;
    }
    mul.erase(mul.find_last_not_of('0') == std::string::npos ? 1 : mul.find_last_not_of('0') + 1);
    return std::string(mul.rbegin() , mul.rend());
}
